package com.sky.mapper;

import com.sky.model.dto.UserDTO;
import com.sky.model.dto.UserPageQueryDTO;
import com.sky.model.entity.User;
import com.sky.model.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 用户注册
     * @param username
     * @param password
     */
    @Insert("insert into user(username,password,created_at) values(#{username},#{password},#{createTime})")
    void register(String username, String password, LocalDateTime createTime);

    /**
     * 根据用户名查询用户是否存在
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    /**
     * 查询用户密码是否正确
     * * @param password
     */
    @Select("select * from user where password = #{password} and username = #{username}")
    User findUser(String username,String password);

    /**
     * 更新用户信息
     * @param user
     */
    void update(User user);

    /**
     * 根据id查询用户信息
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User findById(Long userId);

    /**
     * 分页查询用户信息
     *
     * @param userPageQueryDTO
     * @return
     */
    //List<UserVO> pageQuery(UserPageQueryDTO userPageQueryDTO);

    /**
     * 新增用户信息
     * @param userDTO
     */
    void save(UserDTO userDTO);

    /**
     * 根据id删除用户信息
     * @param id
     */
    @Delete("delete from user where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据时间查询用户
     * @param map
     */
    Integer countByMap(Map map);

    List<UserVO> pageQuery(String name, int offset, int limit);

    long countUsers(String name);
}
